package com.keven.dp.observer;

import java.util.Enumeration;
import java.util.Set;
import java.util.Vector;

public abstract class AbstractSubject implements Subject{
	

	private Vector<Observer> vector = new Vector<Observer>();
	
	
	@Override
	public void add(Observer observer) {
		if (vector.contains(observer)) {
			System.out.println(observer+":is already exit");
		}else {
			vector.add(observer);
		}
	}
	
	@Override
	public void del(Observer observer) {
		if (vector.contains(observer)) {
			vector.remove(observer);
		}else {
			System.out.println(observer+ ":not exit in vector");
		}
	}
	
	@Override
	public void notifyObservers() {
		Enumeration<Observer> enumo = vector.elements();
		while (enumo.hasMoreElements()) {
			Observer observer = (Observer) enumo.nextElement();
			observer.update();
		}
	}
	
}
